package org.foreveross.que.web.action.help;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.foreveross.que.application.SayApplication;
import org.foreveross.que.application.TopicApplication;
import org.foreveross.que.vo.IndexVo;
import org.foreveross.que.web.action.BaseAction;
import org.foreveross.que.web.action.ImportImgBaseAction;
@SuppressWarnings("serial")
@Controller
@org.springframework.context.annotation.Scope("prototype")
@Namespace("/help/chat")
@ParentPackage("json-default")
public class ReplyChatAction extends ImportImgBaseAction {
	
	@Autowired SayApplication sayApplication;
	@Autowired TopicApplication topicApplication;
	IndexVo vo = new IndexVo();
	
	/**
	 * 检索（按某些条件）
	 * @return
	 */
	@Action(value="search", results={@Result(name="JSON", type="json", params={"root","vo.topicVo"})})
	public String search()throws Exception{
		
		super.loadAuthority(vo);
		if(!vo.getWithOutTopic()){
			topicApplication.loadTopic(vo);
		}
		sayApplication.loadReplys(vo);
		vo.getTopicVo().setPageData (vo.getPageData());
		return "JSON"; 
	}
	/**
	 * 回复
	 */
	@Action(value="reply", results={@Result(name="JSON", type="json", params={"root","vo.msg"})})
	public String reply() throws Exception {
		super.loadAuthority(vo);
//		if(IndexVo.ORDER_ROLE.equals(vo.getAuthority())){
//			vo.setMsg("页面过期，请重新从系统进入页面");
//		}
		String content = super.contentDecrypt(vo.getSayVo().getSayInfo());
		vo.getSayVo().setSayInfo(content);
		if(sayApplication.reply(vo)!=null){
			vo.setMsg( "1");
		}else{
			vo.setMsg( "回复失败。");
		}
		return "JSON";
	}
	/**
	 * 设置问题答案
	 * @return
	 * @throws Exception
	 */
	@Action(value="answer", results={@Result(name="JSON", type="json", params={"root","vo.msg"})})
	public String answer() throws Exception{
		super.loadAuthority(vo);
		if(IndexVo.CUSTOMER_SERVICE_ROLE.equals(vo.getAuthority())){
			this.sayApplication.answer(vo);
			vo.setMsg("1");
		}else{
			vo.setMsg("无权限设置。");
		}
		return "JSON";
	}
	
	@Action(value="deleteReply", results={@Result(name="JSON", type="json", params={"root","vo.msg"})})
	public String deleteReply() throws Exception{
		super.loadAuthority(vo);
		this.sayApplication.deleteReply(vo);
		return "JSON";
	}
	
	public IndexVo getVo() {
		return vo;
	}

	public void setVo(IndexVo vo) {
		this.vo = vo;
	}



}
